package com.ucampus.service;

import com.ucampus.dao.ShopDao;
import com.ucampus.entity.ResponseData;
import com.ucampus.entity.Shop;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShopService {
    @Autowired
    private ShopDao shopDao;

    public ResponseData getAll() {
        ResponseData responseData = new ResponseData();
        List<Shop> shops = shopDao.getAll();
        if (!shops.isEmpty()) {
            responseData.setData(shops);
            responseData.setMessage("查询成功");
        }else {
            responseData.setMessage("查询失败，请重试");
        }
        return responseData;
    }

    public ResponseData getByName(String name) {
        ResponseData responseData = new ResponseData();
        List<Shop> shops = shopDao.getByName(name);
        if (!shops.isEmpty()) {
            responseData.setData(shops);
            responseData.setMessage("查询成功");
        }else {
            responseData.setMessage("没有找到内容，换个名试试");
        }
        return responseData;
    }


    public ResponseData add(String name, String location, String message) {
        ResponseData responseData = new ResponseData();
        int n = shopDao.add(name,location,message);
        if (n > 0) {
            responseData.setMessage("添加成功");
        }else {
            responseData.setMessage("添加失败，请重试");
        }
        return responseData;
    }

    public ResponseData update(int id,String name, String location, String message) {
        ResponseData responseData = new ResponseData();
        int n = shopDao.update(id,name,location,message);
        if (n > 0) {
            responseData.setMessage("修改成功");
        }else {
            responseData.setMessage("修改失败，请重试");
        }
        return responseData;
    }

    public ResponseData delete(List<Integer> list) {
        ResponseData responseData = new ResponseData();
        int n = shopDao.delete(list);
        if (n > 0) {
            responseData.setMessage("删除成功");
        }else {
            responseData.setMessage("删除失败，请重试");
        }
        return responseData;
    }
}
